<?php
namespace Admin\Controller;
/**
 * 菜品分类表
 * User: linkwhy
 * Date: 2015/10/16
 * Time: 10:49
 */
 class GoodsClassController extends AdminController{

     public function index(){

         if( !IS_ADMIN ){
            $where['id'] = CLASS_ID;
         }

         $id = I('get.id');
         !empty($id) ? $where['pid'] = $id : $where['pid'] = 0;
         $list   = $this->lists('goods_class', $where);
         int_to_string($list);
         $this->assign('_list', $list);
         $this->assign('pid', !empty($id) ? $id : 0);
         $this->meta_title = '商品分类';
         $this->display();
     }

     public function add(){
         $this->meta_title = '新增分类';
         $this->assign('pid', I('get.pid'));
         $this->assign('_class', $this->getGoodsClassInfo());
         $this->display('update');
     }

     public function edit(){
         $dclass = M('goods_class');
         $data = $dclass->field('id,pid,name,is_patch')->where(array('id' => I('get.id')))->find();
         $data['pid'] = intval($data['pid']);
         $this->meta_title = '修改分类';
         $this->assign('data', $data);
         $this->assign('pid', $data['pid']);
         $this->assign('_class', $this->getGoodsClassInfo());
         $this->display('update');
     }

     public function scale_index(){

         $list   = $this->lists('goods_class', array('is_zk' => 1));
         int_to_string($list);
         $this->assign('_list', $list);
         $this->assign('pid', !empty($id) ? $id : 0);
         $this->meta_title = '商品分类比例';
         $this->display();
     }

     public function scale_add(){
         $this->meta_title = '新增分类比例';
         $this->assign('_class', $this->getGoodsClassInfo());
         $this->display('scale_update');
     }

     public function scale_edit(){
         $data = M('goods_class')->field('id,zhekou')->where(array('id' => I('get.id')))->find();
         $this->assign('_class', $this->getGoodsClassInfo());
         $this->assign('data', $data);
         $this->meta_title = '修改分类比例';
         $this->display('scale_update');
     }

     public function scale_update(){
         $gc = M('goods_class');
         $u_data['is_zk']  = 1;
         $u_data['zhekou'] = I('post.zhekou');
         $cid = I('post.cid');
         $id = I('post.id') > 0 ? I('post.id') : $cid;
         if($gc->where(array('id' => $id))->save($u_data)){
            $this->success('更新成功！', U('scale_index'));
         }
     }

     public function scale_del(){
         $gc = M('goods_class');
         $del['zhekou'] = 0;
         $del['is_zk'] = 0;
         if($gc->where(array('id' => I('get.id')))->save($del)){
             $this->success('删除分类比例成功！');
         }
     }
 }

